package Classes.GameDatas// ActionScript file
{
	import Classes.GameViews.ViewDisplayers.VD_Reward;

	/**
	 *掉落奖励数据类 
	 * @author 葛增文
	 * 
	 */	
	public class GD_Reward extends GameData
	{
		private var _type:int;/*奖励类型*/
		private var _par:Number;/*参数1*/
		private var _view:VD_Reward;
		public static var rewardContainer:Object;
		public function GD_Reward(type:int,par:Number):void
		{
			this._type=type;
			this._par=par;
			if(rewardContainer)
			{
				if(type==0){
					rewardContainer[type]=int(rewardContainer[type])+1;
				}else{
					rewardContainer[type]=int(rewardContainer[type])+par;
				}
			}else{
				rewardContainer=new Object();
				if(type==0){
					rewardContainer[type]=1;
				}else{
					rewardContainer[type]=par;
				}
				
			}
			this.init();
		}
		
		private function init():void
		{
			switch(this.type)
			{
				case 0://物品
					break;
				case 1://行动力
					GD_Player.instance.actPoint=GD_Player.playerNowAction-int(rewardContainer[type]);
					break;
				case 2://金钱
					GD_Player.instance.money=GD_Player.playNowMoney-int(rewardContainer[type]);
					break;
				case 3://O币
					GD_Player.instance.gold=GD_Player.playNowOMoney-int(rewardContainer[type]);
					break;
				case 4://经验
					GD_Player.instance.playerExp=GD_Player.playNowExp-int(rewardContainer[type]);
					break;
			}
		}
		
		/**
		 *创建一个掉落奖励对象 
		 * @param creatObj 创建数据对象
		 * @return 掉落奖励对象
		 * 
		 */		
		public static function creat(creatObj:Object):GD_Reward
		{
			var returnReward:GD_Reward=new GD_Reward(creatObj.type,creatObj.par);
			return returnReward;
		}
		
		public function gainReward():void
		{
			switch(this.type)
			{
				case 0://物品
					var item:GD_Item=GD_Player.instance.getItemByType(this.par);
					var changeNum:int;
					if(item)
					{
						changeNum=item.itemNumber+1;
					}
					else
					{
						changeNum=1;
					}
//					GD_Player.instance.itemNumChanged({itemType:this.par,value:changeNum});
					deleteNumFromRewardContainer(type,1);
					break;
				case 1://行动力
					deleteNumFromRewardContainer(type,par);
					GD_Player.instance.actPoint+=this.par;
					break;
				case 2://金币
					deleteNumFromRewardContainer(type,par);
					GD_Player.instance.money+=this.par;
					break;
				case 3://O币
					deleteNumFromRewardContainer(type,par);
					GD_Player.instance.gold+=this.par;
					break;
				case 4://经验
					deleteNumFromRewardContainer(type,par);
					GD_Player.instance.playerExp+=this.par;
					break;
				
			}
			this.release();
		}
		
		private function deleteNumFromRewardContainer(type:int,par:Number):void
		{
			if(int(rewardContainer[type])>=par)
			{
				rewardContainer[type]=int(rewardContainer[type])-par;
			}
		}
		
		override public function release():void
		{
			super.release();
			if(this._view)
			{
				this._view.release();
				this._view=null;
			}
		}

		/*getter & setter*/
		public function get type():int
		{
			return _type;
		}

		public function get par():Number
		{
			return _par;
		}

		public function get view():VD_Reward
		{
			if(!_view)_view=VD_Reward.creat(this);
			return _view;
		}


	}
}